package com.datang.springcode.beanPostProcessorTest;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

@Component
public class CustomBeanPostProcessor implements BeanPostProcessor, Ordered {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor1,before");
        if (beanName.equals("bright")) {
            Bright bright = (Bright) bean;
            bright.name = "李四";
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor1,after");
        if (beanName.equals("bright")) {
            Bright bright = (Bright) bean;
            bright.name = "王五";
        }
        return bean;
    }

    @Override
    public int getOrder() {
        return 1;
    }
}
